from django.db import models


class Users(models.Model):
    user_id = models.AutoField(primary_key=True)
    user_name = models.CharField(max_length=30)
    user_passwd_hash = models.CharField(max_length=33)
    avatar = models.ImageField(upload_to='avatar/', null=True, default=None)
    tele = models.CharField(max_length=15, unique=True)


class Videos(models.Model):
    video_id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=200)
    video_type = models.PositiveIntegerField()
    describe = models.CharField(max_length=500, null=True, default=None)
    url = models.URLField(null=True, default=None)
    author = models.ForeignKey(Users, models.SET_NULL, null=True, default=None)
    video_cover = models.URLField(null=True, default=None)


class Playlists(models.Model):
    user = models.ForeignKey(Users, models.CASCADE)
    video = models.ForeignKey(Videos, models.CASCADE)
    time = models.DateTimeField(auto_now=True)
    play_time = models.PositiveIntegerField()


class Video_details(models.Model):
    user = models.ForeignKey(Users, models.CASCADE)
    video = models.ForeignKey(Videos, models.CASCADE)
    time = models.DateTimeField(auto_now=True)
    operation_type = models.SmallIntegerField()  # like 1 unlike 2 share 3 favorite 4


class Comment(models.Model):
    id = models.AutoField(primary_key=True)
    user = models.ForeignKey(Users, models.CASCADE)
    video = models.ForeignKey(Videos, models.CASCADE)
    time = models.DateTimeField(auto_now=True)
    allowed = models.BooleanField(default=True)
    content = models.TextField()
